package com.xzm.springboot04web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author 3052
 * @create 2020-08-07 11:52
 */
@Controller
public class LoginController {

    @PostMapping("/user/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String,Object> map, HttpSession httpSession){
            if(!StringUtils.isEmpty(username) && "123456".equals(password)){
                //为了防止表单重复提交，可以设置网页重定向
                httpSession.setAttribute("loginUser",username);
                return "redirect:/main.html";
            }else{
                map.put("msg","用户名或密码错误");
                return "login";
            }
    }

}
